//
//  ConstClassObject.hpp
//  learnC++
//
//  Created by apple on 2018/6/3.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef ConstClassObject_hpp
#define ConstClassObject_hpp

#include <stdio.h>
#include <iostream>
#include <string>
class DoSomething
{
public:
    int m_value;
    
    std::string m_name;
    
    DoSomething() { m_value= 0; }
    
    void resetValue() { m_value = 0; }
    void setValue(int value) { m_value = value; }
    
    //这个const指明了这个函数不会修改该类的任何成员数据的值，称为常量成员函数。
    // note addition of const keyword after parameter list, but before function body
    int getValue() const;
    
    int test(const DoSomething &param);
    
    
    const std::string& getValue2() const { return m_name; } // getValue() for const objects
    std::string& getValue2() { return m_name; } // getValue() for non-const objects
    /*
     DoSomething something;
     something.getValue2() = "Hi"; // calls non-const getValue();
     
     const DoSomething something2;
     something2.getValue2(); // calls const getValue();
     */
    
};




/*
 
 //调用
 const DoSomething so;
 so.getValue();
 
 
 NOTE:按值传递类参数会导致创建一个类的副本（这很慢）可以使用const reference
 // note: We're passing date by const reference here to avoid making a copy of date
 void printDate(const Date &date)
 {
 std::cout << date.getYear() << "/" << date.getMonth() << "/" << date.getDay() << '\n';
 }
 
 int main()
 {
 Date date(2016, 10, 16);
 printDate(date);
 
 return 0;
 }
 */


#endif /* ConstClassObject_hpp */
